import React, { Component } from 'react'
import axios from 'axios'
import MainBanner from './MainBanner'
import MainProductList from './MainProductList'

export default class Main extends Component {
  // constructor: 构造函数初始化数据
  constructor() {
    super()

    this.state = {
      banners: [],
      productList: []
    }
  }

  // componentDidMount: 组件挂载完成
  componentDidMount() {
    // 发送请求获取数据
    axios.get("http://123.207.32.32:8000/home/multidata").then(res => {
      const banners = res.data.data.banner.list
      const productList = res.data.data.recommend.list
      this.setState({
        banners,
        productList
      })
    })
  }
  
  render() {
    const { banners, productList } = this.state
    console.log(banners, productList);
    
    return (
      <div className='main'>
        <div>Main</div>
        <MainBanner banners={banners} title="轮播图"></MainBanner>
        <MainProductList productList={productList} title="商品列表"></MainProductList>
      </div>
    )
  }
}
